package com.yjd.comm.base.concurrent.task;

import java.util.concurrent.CountDownLatch;

/**
 * 任务处理线程
 * 
 * @author ready
 * @date 2014-8-8
 */
public class TaskDisposer implements Runnable {

	/**
	 * 处理原子计数器
	 */
	private CountDownLatch countDownLatch;
	/**
	 * 处理器
	 */
	@SuppressWarnings("rawtypes")
	private ITaskHandler taskHandler;
	/**
	 * 任务对象
	 */
	@SuppressWarnings("rawtypes")
	private ITaskItem taskItem;

	@SuppressWarnings("rawtypes")
	public TaskDisposer(CountDownLatch countDownLatch,
			ITaskHandler taskHandler, ITaskItem taskItem) {
		this.countDownLatch = countDownLatch;
		this.taskHandler = taskHandler;
		this.taskItem = taskItem;
	}

	@SuppressWarnings("unchecked")
	@Override
	public void run() {
		try {
			taskHandler.dispose(this.taskItem);
		} finally {
			this.countDownLatch.countDown();
		}
	}
}